package com.pdg.dungeondelver.client;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import com.pdg.dungeondelver.configuration.Configuration;

public class SplashState extends BaseGameState{

	private static final String BACKGROUND_IMAGE = "background-splash";
	private static final Integer SPLASH_TIMER = 5000;
	private static final float BACKGROUND_X = 0;
	private static final float BACKGROUND_Y = 0;

	public SplashState(Configuration theConfiguration,Client theClient, States theState){
		super(theConfiguration,theClient,theState);
	}
	private Integer elapsed = 0;
	
	@Override
	public void keyPressed(int arg0, char arg1) {
		super.keyPressed(arg0, arg1);
		if(arg0==Input.KEY_ESCAPE){
			elapsed = SPLASH_TIMER;
		}
	}

	@Override
	public void enter(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		super.enter(gc,sbg);
		elapsed = 0;
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
			throws SlickException {
		getConfiguration().getImageManager().getImage(BACKGROUND_IMAGE).draw(BACKGROUND_X,BACKGROUND_Y);
		super.render(gc, sbg, g);
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta)
			throws SlickException {
		super.update(gc, sbg, delta);
		elapsed+=delta;
		if(elapsed>=SPLASH_TIMER){
			sbg.enterState(States.MAINMENU.getIndex());
		}
	}

}
